package com.lz.sports.adapter

import android.view.View
import android.view.ViewGroup
import com.lz.library.adapter.BindingAdapter
import com.lz.library.adapter.BindingViewHolder
import com.lz.sports.BR
import com.lz.sports.R
import com.lz.sports.bean.DeviceInfo
import com.lz.sports.databinding.ItemGroupBindBinding
import com.lz.sports.widget.ShakeClickListener

//设备分组绑定
class GroupBindAdapter : BindingAdapter<DeviceInfo>() {

    var itemBindListener: OnItemBindListener? = null

    override fun getLayoutResId(viewType: Int): Int = R.layout.item_group_bind

    override fun getVariableId(viewType: Int): Int = BR.device

    override fun onCreateItem(parent: ViewGroup, viewType: Int): BindingViewHolder {
        val vh = super.onCreateItem(parent, viewType)
        vh.getBinding<ItemGroupBindBinding>().tvBind.setOnClickListener(object : ShakeClickListener() {
            override fun shakeClick(v: View) {
                val position = vh.bindingAdapterPosition
                if (position < 0) return
                itemBindListener?.onItemBind(position)
            }
        })
        return vh
    }

    //绑定点击
    interface OnItemBindListener {

        fun onItemBind(position: Int)
    }
}